package com.axin.auth.controller;

import com.axin.auth.service.SysLoginService;
import com.axin.common.core.constant.Constants;
import com.axin.common.core.constant.SecurityConstants;
import com.axin.common.core.domain.model.LoginBody;
import com.axin.common.core.domain.web.AjaxResult;
import com.axin.common.redis.utils.RedisUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * 授权 控制
 *
 * @Author 阿欣
 * @Date 2021/8/18 18:58
 */
@RestController
@RequestMapping("/auth")
public class AuthController {


    @Autowired
    private SysLoginService loginService;

    /**
     * 登录方法
     *
     * @param loginBody 登录信息
     * @return 结果
     */
    @PostMapping("/login")
    public AjaxResult login(@RequestBody LoginBody loginBody) {

        // 生成令牌
        String token = loginService.login(loginBody);

        Map<String, Object> ajax = new HashMap<>(1);
        ajax.put(SecurityConstants.TOKEN, token);
        return AjaxResult.success(ajax);
    }

}
